define(["validate"], function() {
	return {
		title: ['<a href="user.html">个人中心</a>', "修改头像"],
		init: function(content) {
			let form = content.find("form");
			$.get(
				"user/info.do",
				function(data) {
					data.userSex = "" + data.userSex;
					$.each(data, function(name, value) {
						content.find("[name='" + name + "']").val(value);
					});
					validateForm();
				}, "json"
			);

			let validateForm = function() {
				form.bootstrapValidator({
					//container: 'tooltip',
//					feedbackIcons: {
//						valid: 'glyphicon glyphicon-ok',
//						invalid: 'glyphicon glyphicon-remove',
//						validating: 'glyphicon glyphicon-refresh'
//					},
					fields: {
						userRealName: {
							validators: {
								notEmpty: {
									message: "昵称不能为空"
								}
							}
						}
					}
				}).on("success.form.bv", function() {
					$.post(
						"user/my-info.do",
						form.serializeArray(),
						function(data) {
							if(data.ok) {
								toastr.success("修改个人资料成功");
								
							} else {
								toastr.error(data.message);
							}
						}, "json"
					);
					return false;
				});
			}

		}
	}
});